home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / GRSOUNIT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  3.5 KB  |  125 lines

  1. #include "grsounit.h"
  2.  
  3. // grsounit.cpp: Graphics-Based Rectangular Screen Object Definitions
  4. // These routines use the built-in rectangle to clip the 
  5. // transfers. They also take care of the mouse cursor as well.  
  6.  
  7. Grso::Grso(void)
  8. // Initializes a Grso object. Note: It saves the height of the current
  9. // font being used. This font style is assumed to be the currently
  10. // registered font while this Grso object is being used. 
  11. : Rso(0, 0, 0, 0)
  12. {
  13.   TxtHt = ::textheight("H") * 4 / 3;
  14. }
  15.  
  16. void Grso::HzWrt(int X, int Y, char *Str, char Attr)
  17. // Writes a string to a Grso object. The string is clipped to
  18. // the boundaries of the object. The text is displayed using
  19. // the foreground color of the Attr parameter. The region below
  20. // the text is cleared using the background color of Attr. 
  21. {
  22.   int W, H; 
  23.   viewporttype Vp;
  24.  
  25.   getviewsettings(&Vp);
  26.   W = TextWidth(Str);
  27.   setviewport(Xul,Yul,Xlr,Ylr,1);
  28.   H = TextHeight(1);
  29.   FillB(X, Y, W, H, Attr, 1);
  30.   Mouse.Hide();
  31.   setcolor(ForeGround(Attr));
  32.   outtextxy(X, Y, Str);
  33.   setviewport(Vp.left, Vp.top, Vp.right, Vp.bottom, Vp.clip);
  34.   Mouse.Show();
  35. }
  36.  
  37. void Grso::HzWrtB(int X, int Y, char *Str)
  38. // Writes a string to this object. The string is clipped. Note that
  39. // this routine does not clear the space where the text is displayed
  40. // and that it uses the current drawing color--whatever it may be. 
  41. {
  42.   viewporttype Vp;
  43.   getviewsettings(&Vp);
  44.   setviewport(Xul,Yul,Xlr,Ylr,1);
  45.   Mouse.Hide();
  46.   outtextxy(X, Y, Str);
  47.   Mouse.Show();
  48.   setviewport(Vp.left, Vp.top, Vp.right, Vp.bottom, Vp.clip);
  49. }
  50.  
  51. void Grso::Fill(int X, int Y, int W, int H,  char, char Attr)
  52. // Fills a region with a particular color. Note: The unnamed
  53. // parameter, which should be the fill character, is ignored.
  54. {
  55.   if (((H == 1) && HzClip(X, Y, W)) ||
  56.       ((W == 1) && VtClip(X, Y, H)) ||
  57.       (VtClip(X,Y,H) && HzClip(X,Y,W)))  {
  58.      Mouse.Hide();
  59.      setfillstyle(SOLID_FILL,BackGround(Attr));
  60.      bar(Xul+X, Yul+Y, Xul+X+W-1, Yul+Y+H-1);
  61.      Mouse.Show();
  62.   }
  63. }
  64.  
  65. void Grso::FillB(int X, int Y, int W, int H, char Ch, char)
  66. // Fills a region. Note: This interpretation is different than
  67. // its text-mode counterpart in trsounit.cpp. The last parameter,
  68. // which is the Opt parameter, is ignored.
  69. {
  70.   Fill(X, Y, W, H, ' ', Ch);
  71. }
  72.  
  73. void Grso::Box(int X, int Y, int W, int H, char Ba, char Attr)
  74. // Draws a box
  75. {
  76.   unsigned char Bw, Bs, B;
  77.   int I, Xs, Ys, Xf, Yf;
  78.  
  79.   Bw = Ba & 0x000f;          // Unpack the border width
  80.   Bs = (Ba >> 4) & 0x000f;   // and the border style
  81.   if ((Bs > 0) && (Bs < 4)) {
  82.      Mouse.Hide();
  83.      if (Bs == 1) {
  84.     for (I = 0; I < Bw; I++) {
  85.       setcolor(ForeGround(Attr));
  86.       rectangle(Xul+X, Yul+Y, Xul+X+W-1, Yul+Y+H-1);
  87.       X++; Y++; W -= 2; H -= 2;
  88.     }
  89.      }
  90.      else { // Use a 3D style
  91.        if ((Bs << 4) == Recessed) {
  92.       B = ForeGround(Attr);
  93.       Attr = BackGround(Attr) + (B << 4);
  94.        }
  95.        Xs = X+Xul; Xf = Xs + W - 1;
  96.        Ys = Y+Yul; Yf = Ys + H - 1;
  97.        for (I = 0; I < Bw; I++) {
  98.      setcolor(BackGround(Attr));
  99.      moveto(Xs+I, Yf-I);
  100.      lineto(Xs+I, Ys+I);
  101.      lineto(Xf-I, Ys+I);
  102.      setcolor(ForeGround(Attr));
  103.      moveto(Xf-I, Ys+I+1);
  104.      lineto(Xf-I, Yf-I);
  105.      lineto(Xs+I+1, Yf-I);
  106.        }
  107.      }
  108.      Mouse.Show();
  109.   }
  110. }
  111.  
  112. int Grso::TextWidth(char *Str)
  113. // Returns the pixel width of a string 
  114. {
  115.   return ::textwidth(Str);
  116. }
  117.  
  118. int Grso::TextHeight(int N)
  119. // Returns the pixel height of N rows of text 
  120. {
  121.   return TxtHt*N;
  122. }
  123.  
  124.  
  125.